package com.parsechina.hpush.broker.config;

import com.parsechina.hpush.broker.internal.unique.UniqueId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 唯一ID配置
 * @author linfeng
 */
@Configuration
@EnableConfigurationProperties(UniqueIdProperties.class)
public class UniqueIdConfiguration {

    @Autowired
    private UniqueIdProperties uniqueIdProperties;

    @Bean
    @ConditionalOnMissingBean(UniqueId.class)
    public UniqueId uniqueId() {
        return new UniqueId(uniqueIdProperties.getWorkerId(), uniqueIdProperties.getDataCenterId());
    }

}
